import axios from 'axios';

var hasNetWork = true;

// 创建axios实例
const service = axios.create({
  // baseURL: process.env.BASE_API, // api的base_url
  // baseURL: "http://192.168.0.65:3322",
  timeout: 600000, // 请求超时时间
});
// request拦截器
service.interceptors.request.use(config => {

  return config;
}, error => {
  // Do something with request error
  //console.log(error); // for debug
  Promise.reject(error);
})

// respone拦截器
service.interceptors.response.use(
  response => {
    // response.headers['Content-Type'] = "application/x-www-form-urlencoded;charset=UTF-8"

    if (response.status === 200 || response.status === 304) {
      return response.data;
    } else {
      console.log('status:' + response.status)
      // console.log('网络不太给力哦，检查一下您的网络再试吧！')
    }
  },
  error => {
    console.log('err' + error); // for debug
    if (hasNetWork) {
      hasNetWork = false;
      // alert('网络不太给力哦，检查一下您的网络再试吧！')
    }
    return Promise.reject(error);
  }
);
export default service;
